* Sorens http://www.statepolicyindex.com/data/


**********************************************************
* tort laws
**********************************************************
import excel "File_Extension\o_courts_17.xlsx", sheet("Data") cellrange(A2:AB852) firstrow clear

tab1 opuncap opunburd ojsl

keep if Year <=2016   
   
tab1 opuncap opunburd ojsl
   
* all scored high = anti-corporate (like higher tax rates)  
recode opuncap  (1=.5)(2=0)(0=1), gen(pun_cap)
recode opunburd (3=0)(2=.33)(1=.67)(0=1), gen(pun_burd)
recode ojsl     (1=0)(2=0)(0=1), gen(joint_lia)

tab1 pun_cap pun_burd joint_lia

gen tort3 = (pun_cap + pun_burd + joint_lia)/3
tab tort3

export delimited tort3 State Year pun_cap pun_burd joint_lia opuncap opunburd ojsl using "File_Extension\tort3.csv", nolabel replace

**********************************************************
* eminent domain
**********************************************************
import excel "File_Extension\f_land_17.xls", sheet("Data") cellrange(A2:AL852) firstrow clear

keep if Year <=2016 
tab1 freform fprivate fblight fconst

* all scored high = anti-corporate (like higher tax rates)  
gen emdom3 = (freform + fprivate + fblight)/3

export delimited emdom3 State Year freform fprivate fblight fconst using "File_Extension\emdom3.csv", nolabel replace

**********************************************************
* gun laws
**********************************************************

 import excel "File_Extension\b_guns_17.xlsx", sheet("Data") cellrange(A2:AW1552) firstrow clear
 
 keep if year >= 2000
 
 * use codebook command to see whihc vars have missing data
 * codebook
 
 pwcorr bccpir bsi btrain Bplaces-Bprecc Basslt-Brifle ///
    Bminage-bssp botheft-Blicens Bregis-Blocks Bballist-Bretent Bconst bssp-bsbs
	
* create 0-100 index with high score as stricter gun laws (more liberal)'
recode bccpir (2=0)(1=.5)(0=1), gen(Rbccpir) 
recode bsi    (2=0)(1=.5)(0=1), gen(Rbsi) 
recode Bopen  (2=0)(1=.5)(0=1), gen(RBopen) 
*
recode Bplaces(1=0)(.5=.5)(0=1), gen(RBplaces) 
recode Bpreoc (1=0)(.5=.5)(0=1), gen(RBpreoc) 
recode Bprecc (1=0)(.5=.5)(0=1), gen(RBprecc) 
recode bdtr   (1=0)(.5=.5)(.75=.5)(0=1), gen(Rbdtr) 
recode bmg    (1=0)(.5=.5)(0=1), gen(RBbmg) 
recode bss    (1=0)(.5=.5)(0=1), gen(Rbssp) 
recode bsbr   (1=0)(.5=.5)(0=1), gen(Rbsbr) 
recode bsbs   (1=0)(.5=.5)(0=1), gen(Rbsbs) 
*
recode Bjourn (3=0)(2=.5)(1=1), gen(RBjourn) 
*
recode Blocks (2=1)(1=.5)(0=0), gen(RBlocks)

tab1 Rbccpir-RBlocks btrain Basslt-Brifle Bminage-bssp botheft-Blicens Bregis Bdesign Bballist Bretent

egen gunsT = rowmean(Rbccpir-RBlocks btrain Basslt-Brifle Bminage-bssp botheft-Blicens Bregis Bdesign Bballist Bretent)
gen  guns30 = 100*gunsT
sum  guns30

**************

pwcorr guns30 Rbccpir-RBlocks btrain Basslt-Brifle Bminage-bssp botheft-Blicens Bregis Bdesign Bballist Bretent

export delimited using "File_Extension\guns.csv", replace
